package com.threefish.common.plugins.shiro;

import org.apache.shiro.authc.UsernamePasswordToken;

/**
 * @author 黄川 huchuc@vip.qq.com
 * @date: 2018/9/7
 */
public class ShiroUserToken extends UsernamePasswordToken {

    private static final long serialVersionUID = -1L;
    /**
     * 登录类型
     */
    private LoginType loginType;

    /**
     * Constructs a new UsernamePasswordToken encapsulating the username and password submitted
     * during an authentication attempt, with a <tt>null</tt> {@link #getHost() host} and
     * a <tt>rememberMe</tt> default of <tt>false</tt>
     * <p/>
     * <p>This is a convience constructor and maintains the password internally via a character
     * array, i.e. <tt>password.toCharArray();</tt>.  Note that storing a password as a String
     * in your code could have possible security implications as noted in the class JavaDoc.</p>
     *
     * @param username the username submitted for authentication
     * @param password the password string submitted for authentication
     */
    public ShiroUserToken(String username, String password, LoginType loginType) {
        super(username, password);
        this.loginType = loginType;
    }

    public LoginType getLoginType() {
        return loginType;
    }

    public void setLoginType(LoginType loginType) {
        this.loginType = loginType;
    }

    /**
     * 判断是否验证密码规则
     *
     * @return
     */
    public boolean needVerifyPass() {
        //不是扫描登录或单点登录的不效验密码规则
        return !(this.getLoginType() == LoginType.QrLogin || this.getLoginType() == LoginType.SSO);
    }
}
